/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interpreter.Function;

import Interpreter.InterpreterVisitor;
import ast.*;
import java.util.ArrayList;

/**
 *
 * @author Stephen
 */
public class WithinFunction extends Function {
    
    @Override
    public Object execute(ArrayList args) {
        Object v = ((AST)args.get(0)).accept(new InterpreterVisitor());
        Object a = ((AST)args.get(1)).accept(new InterpreterVisitor());
        Object b = ((AST)args.get(2)).accept(new InterpreterVisitor());
        
        String type = InterpreterVisitor.parseType((String) v);
        
        if (type.equalsIgnoreCase("float")) {
            if (Float.parseFloat((String) v) < Float.parseFloat((String)a)) {
                return false;
            } else if (Float.parseFloat((String) b) < Float.parseFloat((String)v)) {
                return false;
            }
            return true;
        } else if (type.equalsIgnoreCase("int")) {
            if (Integer.parseInt((String) v) < Integer.parseInt((String)a)) {
                return false;
            } else if (Integer.parseInt((String) b) < Integer.parseInt((String)v)) {
                return false;
            }
            return true;
        }
        
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
